package com.sptpc.stu.controller;

import com.sptpc.stu.model.Course;
import com.sptpc.stu.repository.CourseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cur")
public class CourseController {
    @Autowired
    private CourseRepository courseRepository;

    // 新建课程，json格式传数据
    @PostMapping(value = "/add", consumes = MediaType.APPLICATION_JSON_VALUE)
    public Course addNewCourse(@RequestBody Course course) {
        // 课程信息写入数据库
        courseRepository.save(course);
        return course;
    }

    // 得到所有的课程
    @GetMapping(value = "/")
    public List<Course> getAllCourse() {
        return courseRepository.findAll();
    }

}
